package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.data.entity.UcenterEntity;
import com.runen.wnhz.runen.widget.flowtaglayout.OnInitSelectedPosition;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 描述：
 * 作者： 天天童话丶
 * 时间： 2018/5/31.
 */

public class BalanceAdapter extends BaseAdapter implements OnInitSelectedPosition {

    private final Context mContext;
    private final List<UcenterEntity> mDataList;

    public BalanceAdapter(Context context) {
        this.mContext = context;
        mDataList = new ArrayList<>();
    }

    public BalanceAdapter(Context context, List<UcenterEntity> data) {
        this.mContext = context;
        if (data != null && !data.isEmpty()){
            mDataList = data;
        } else {
            mDataList = new ArrayList<>();
        }
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.balance_activity_item, null);

        TextView textView = (TextView) view.findViewById(R.id.tv_price);
        //文本单行显示，过长时中间...省略
        textView.setSingleLine(true);
        textView.setEllipsize(TextUtils.TruncateAt.MIDDLE);

        UcenterEntity t = mDataList.get(position);
        textView.setText(t.getTitle());

        return view;
    }

    public void onlyAddAll(List<UcenterEntity> datas) {
        mDataList.addAll(datas);
        notifyDataSetChanged();
    }

    public void clearAndAddAll(List<UcenterEntity> datas) {
        mDataList.clear();
        onlyAddAll(datas);
    }

    @Override
    public boolean isSelectedPosition(int position) {
        return false;
    }

    public List<UcenterEntity> getData() {
        return mDataList;
    }
}
